package com.markerhub.common;

import java.util.ArrayList;
import java.util.List;

/** 
 类说明 : API 统一返回状态码
*/
public enum ResponseCode {

	/* 成功 - 失败 状态码 */
    SUCCESS(0, "请求成功"),
    FAILURE(1, "请求失败"),

    /* 参数错误：101-199 */
    PARAM_IS_INVALID(101, "参数无效"),
    PARAM_IS_BLANK(102, "参数为空"),
    PARAM_TYPE_BIND_ERROR(103, "参数类型错误"),
    PARAM_NOT_COMPLETE(104, "参数缺失"),
    PARAM_MOBILE_FORMATERROR(105, "手机号码为空或格式不正确"),
    PARAM_WXOPENID_EMPTY(106, "获取微信openid失败或为空"),

    /* 用户错误：201-299*/
    USER_NOT_LOGGED_IN(201, "用户未登录"),
    USER_LOGIN_ERROR(202, "账号不存在或密码错误"),
    USER_ACCOUNT_FORBIDDEN(203, "账号已被禁用"),
    USER_NOT_EXIST(204, "用户不存在"),
    USER_HAS_EXISTED(205, "用户已存在"),
    USER_VERIFICATION_CODE_ERROR(206,"验证码错误"),

    /* 业务错误：301-399 */
    SPECIFIED_QUESTIONED_USER_NOT_EXIST(301, "业务录入出现问题，请稍候再试"),

    /* 系统错误：401-499 *
    SYSTEM_INNER_ERROR(401, "系统繁忙，请稍后重试"),

    /* 数据错误：501-599 */
    RESULE_DATA_NONE(501, "未找到数据"),
    DATA_IS_WRONG(502, "数据有误"),
    DATA_ALREADY_EXISTED(503, "数据已存在"),

    /* 接口错误：601-699 */
    INTERFACE_INNER_INVOKE_ERROR(601, "内部系统接口调用异常"),
    INTERFACE_OUTTER_INVOKE_ERROR(602, "外部系统接口调用异常"),
    INTERFACE_FORBID_VISIT(603, "该接口禁止访问"),
    INTERFACE_ADDRESS_INVALID(604, "接口地址无效"),
    INTERFACE_REQUEST_TIMEOUT(605, "接口请求超时"),
    INTERFACE_EXCEED_LOAD(606, "接口负载过高，请稍后再试"),

    /* 权限错误：701-799 */
    PERMISSION_NO_ACCESS(701, "无访问权限");

    private Integer code;
    private String message;

    ResponseCode(Integer code, String message) {
    	
        this.code = code;
        this.message = message;
    }

    public Integer code() {
    	
        return this.code;
    }

    public String message() {
    	
        return this.message;
    }

    public static String getMessage(String name) {
    	
        for (ResponseCode item : ResponseCode.values()) {
            if (item.name().equals(name)) {
            	
                return item.message;
            }
        }
        return name;
    }

    public static Integer getCode(String name) {
    	
        for (ResponseCode item : ResponseCode.values()) {
            if (item.name().equals(name)) {
            	
                return item.code;
            }
        }
        return null;
    }

    @Override
    public String toString() {
    	
        return this.name();
    }

    //校验重复的code值
    public static void main(String[] args) {
    	
        ResponseCode[] ApiResultCodes = ResponseCode.values();
        List<Integer> codeList = new ArrayList<Integer>();
        for (ResponseCode ApiResultCode : ApiResultCodes) {
        	
            if (codeList.contains(ApiResultCode.code)) {
            	
                System.out.println("重复的code值" + ApiResultCode.code);
            } else {
            	
                codeList.add(ApiResultCode.code());
            }
        }
    }
}
